#!/usr/bin/python env
# -*- coding: utf-8 -*-
# @Time   :2018/4/27 23:50
# @Author :huchao


class Student:
    '''
    创建一个学生类
    有三个属性，name,age,score
    有如下方法
    '''
    __student_count = 0  # 初始化学生数量

    docs = list()

    __slots__ = ["__name", "__age", "__score","__address"]

    def __init__(self, name, age, score,address="未填写"):
        try:
            self.__NumberCheck(name,age,score)
        except AssertionError as err:
            print(err)
            return
        self.__name = name
        self.__age = age
        self.__score = score
        self.__address = address
        self.__class__.__student_count += 1
        self.__class__.docs.append(self)

    def __del__(self):

        self.__class__.__student_count -= 1

    def __str__(self):

        return "{},{},{}".format(self.__name,self.__age,self.__score)

    @staticmethod
    def __NumberCheck(name=None, age=None, score=None):
        if not age:
            assert 0 <= age <= 140, "年龄不合法，再来一次"
        if not score:
            assert 0 <= score <= 100, "成绩不合法，再来一次"
        if not name:
            assert 0<=len(name)<=32,"name长度不合法，再来一次"


    @classmethod
    def get_student_count(cls):
        return cls.__student_count

    @classmethod
    def getStudentList(cls):
        '''
        此方法是类方法。用来返回类属性学生列表
        :return:
        '''
        return cls.docs

    def getStudentName(self):
        '''返回学生名字'''
        return self.__name

    def getStudentage(self):
        '''返回学生年龄'''
        return self.__age

    def getStudentScore(self):
        '''返回学生成绩'''
        return self.__score

    def setStudentScore(self, score):
        '''修改学生成绩'''

        self.__score = score

    def getStudentAddres(self):

        return self.__address

    def setStudentAddres(self,addres):

        self.__address = addres



    @classmethod
    def getStudentArry(cls):
        '''用元组的形式返回学生信息'''

        return [S.lstrip("__") for S in  cls.__slots__]


    def writeInfoToFile(self,file):
        file.write("{},{},{}\n".format(self.__name,str(self.__age),str(self.__score)))

    @classmethod
    def readStudentListForFile(cls,file):
        while True:
            Str = file.readline()
            if not Str:
                break
            L = Str.rstrip("\n").split(",")
            for stu  in cls.docs:
                if L[0] == stu.__name:
                    continue
            Student(*L)